package top.jacktgq.cas;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
 * 
 * @Title: AtomicFieldUpdaterDemo.java 
 * @Package top.jacktgq.cas 
 * @Description: 原子字段更新器
 * @author CandyWall   
 * @date 2020年11月3日 上午10:58:02 
 * @version V1.0
 */
public class AtomicFieldUpdaterDemo {
	public static void main(String[] args) {
		Student stu = new Student();
		AtomicReferenceFieldUpdater<Student, String> updater 
					= AtomicReferenceFieldUpdater.newUpdater(Student.class, String.class, "name");
		System.out.println(updater.compareAndSet(stu, null, "张三"));
		System.out.println(stu);
	}
}

class Student {
	volatile String name;

	@Override
	public String toString() {
		return "Student [name=" + name + "]";
	}
}
